<template>
  <div id="RoutineDetails">
    <v-tableTitle
      :btnConfig="btnConfig"
      @closeSave='closeSave'
      @save='save'
    ></v-tableTitle>
    <v-detail
      :detailData="inputData.detailDataFpkw"
      :inputConfig="inputConfig"
      :rules="rules"
      @pop="setData"
      ref="input"
    ></v-detail>
  </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";
import tableTitle from "@/components/commons/TableTitle";
export default {
  name: "RoutineDetails",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object
    }
  },
  data () {
    return {
      rules: {
        loc: [
          { required: true, trigger: 'blur' },
        ],
        locationtype: [
          { required: true, trigger: 'blur' },
        ],
        qtylocationminimum: [
          { required: true, validator: this.verify, trigger: 'blur' },
        ],
        qtylocationlimit: [
          { required: true, validator: this.verify, trigger: 'blur' },
        ],
        qtyreplenishmentoverride: [
          { required: true, validator: this.verify, trigger: 'blur' },
        ],

      },
    }
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('common.save'), invalid: "save" },
        { label: this.$t('common.cancel'), invalid: "closeSave" },
      ]
    },
    inputConfig () {
      return [
        [
          {
            type: "table",
            label: this.$t('config.loc'),
            props: "loc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input"
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCTYPE")
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions("queryPutawayzoneDropDown")
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCFLAG")
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCCATEGRY")
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('config.commingleLot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              }
            ],
            url: 'queryLoc/',
            readonly: true,
            disabled: !this.$parent.fpkwFlag
          },
          {
            type: "select",
            label: this.$t('config.replenishmentuom'),
            props: "replenishmentuom",
            options: this.getOptions("codelkup/EAIPCA")
          },
          {
            type: "input",
            label: this.$t('config.qtyreplenishmentoverride'),
            props: "qtyreplenishmentoverride",
          },
        ],
        [
          {
            type: "select",
            label: this.$t('config.locType'),
            props: "locationtype",
            options: this.getOptions('querycodeLkup/LOCTYPE')
          },
          {
            type: "input",
            label: this.$t('config.replenishmentpriority'),
            props: "replenishmentpriority",
            disabled: true
          },
        ],
        [
          {
            type: "input",
            label: this.$t('config.qtylocationminimum'),
            props: "qtylocationminimum",
          },
          {
            type: "input",
            label: this.$t('config.replenishmentseverity'),
            props: "replenishmentseverity",
            disabled: true
          },

        ],
        [
          {
            type: "input",
            label: this.$t('config.qtylocationlimit'),
            props: "qtylocationlimit",
          },
          {
            type: "checkbox",
            label: this.$t('config.allowreplenishfromcasepick'),
            props: "allowreplenishfromcasepick",
          },
          {
            type: "checkbox",
            label: this.$t('config.allowreplenishfrombulk'),
            props: "allowreplenishfrombulk",
          },
          {
            type: "checkbox",
            label: this.$t('config.allowreplenishfrompiecepick'),
            props: "allowreplenishfrompiecepick",
          },
        ]
      ]
    }
  },
  methods: {
    save () {
      this.$refs.input.$refs["from"].validate((valid) => {
        if (valid) {
          let url = ''
          let data = {
            ...this.inputData.detailDataFpkw,
            storerkey: this.inputData.detailData.storerkey,
            sku: this.inputData.detailData.sku
          }
          if (this.$parent.fpkwFlag) {
            url = '/insertSkuxlocsingle'
          } else {
            url = '/updateSkuxlocsingle'
          }
          this.$api.post(url, data).then(res => {
            
              this.$message.success(res.returnMgr);
              this.closeSave()
          })
        }
      })

    },
    closeSave () {
      this.$parent.setMentActive('8')
    },
    verify (rule, value, callback) {
      if (value === '') {
        this.$message.error(this.$t('app.dataIsNotNull'))
          //修改bug:960 注释该代码
        // this.inputData.detailDataFpkw[rule.field] = 0
        callback(new Error());
      } else {
        var re = /^[0-9]\d*$/;
        let te = value;
        let flag = re.test(te)
        if (!flag) {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
            //修改bug:960 注释该代码
          // this.inputData.detailDataFpkw[rule.field] = 0
          callback(new Error());
        } else {
          callback();
        }
      }
    },
    setData (data, id, close, listId) {
      if (id == 0 && listId == 0) {
        this.inputData.detailDataFpkw.loc = data.loc
      }
      close(false);
    }
  },
  mounted () {
  },
  watch: {

  },
  components: {
    "v-detail": detail,
    "v-tableTitle": tableTitle,
  }
}
</script>

<style scoped>
</style>
